<?php
class Application_Model_DbTable_List extends Zend_Db_Table_Abstract
{

	protected $_name = 'list';

	private function _makeUp($data)
	{
		$newData = array();
		$newData['name'] = $data['name'];
		$newData['owner_name'] = $data['owner_name'];
		$newData['owner_email'] = $data['owner_email'];
		$newData['reply_email'] = $data['reply_email'];

		return $newData;
	}

	public function getAllList()
	{
		$result = array();

		$data = $this->fetchAll()->toArray();

		foreach ($data as $value)
		{
			$id = $value['id'];

			$result[$id] = $value['name'];
		}

		return $result;
	}

	public function getSomeList($ids)
	{
		if (!is_array($ids))
		{
			$ids = array($ids);
		}

		$result = array();

		foreach ($ids as $id)
		{
			$id = (int)$id;
			$data = $this->getList($id);
			$result[$id] = $data['name'];
		}

		return $result;
	}

	public function getList($id)
	{
		$id = (int)$id;
		$row = $this->fetchRow('id = ' . $id);
		if (!$row)
		{
			throw new Exception("Could not find row $id");
		}
		return $row->toArray();
	}

	public function addList($data)
	{
		$data = $this->_makeUp($data);
		$this->insert($data);
	}

	public function updateList( $id, $data)
	{
		$data = $this->_makeUp($data);
		$this->update($data, 'id = '. (int)$id);
	}

	public function deleteList($id)
	{
		$this->delete('id =' . (int)$id);
	}

}